#============================================================
#	Node 2D Util
#============================================================
# @datetime: 2022-4-21 22:17:44
#============================================================

class_name Node2DUtil



static func direction_to(a: Node2D, b: Node2D) -> Vector2:
	return a.global_position.direction_to(b.global_position)

static func angle_to(a: Node2D, b: Node2D) -> float:
	# 当前面向角度到目标位置之间的夹角
	return a.global_position.angle_to(b.global_position)

static func angle_to_point(a: Node2D, b: Node2D) -> float:
	return a.global_position.angle_to_point(b.global_position)

static func distance_to(a: Node2D, b: Node2D) -> float:
	return a.global_position.distance_to(b.global_position)

static func distance_squared_to(a: Node2D, b: Node2D) -> float:
	return a.global_position.distance_squared_to(b.global_position)

##  获取距离最近的节点
## @node  2D节点
## @node_list  2D节点列表
## @return  
static func get_closest_node(node: Node2D, node_list: Array) -> Node2D:
	if node_list.size() == 0:
		return null
	elif node_list.size() == 1:
		return node_list[0]
	var min_distance : float = INF
	var pos = node.global_position
	var dist : float
	var min_distance_node : Node2D = null
	for n in node_list:
		dist = pos.distance_squared_to(n.global_position)
		if min_distance > dist:
			min_distance = dist
			min_distance_node = n
	return min_distance_node

